from __future__ import absolute_import, unicode_literals

import os
from celery import Celery, platforms

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'didiTaxiPython.settings')
app = Celery('didiTaxiPython', broker='redis://127.0.0.1:6379/1',  # 任务存放的地方
             backend='redis://127.0.0.1:6379/15')

app.config_from_object('django.conf:settings')

app.autodiscover_tasks()

platforms.C_FORCE_ROOT = True

# from celery import Celery
# from elasticsearch import Elasticsearch
#
#
# app = Celery('tasks', broker='redis://localhost:6379/0', backend='redis://localhost:6379/0')
#
#
# @app.task
# def update_es(data):
#     es = Elasticsearch(['http://localhost:9200'])
#     # 根据数据的操作类型（添加/修改/删除）更新 ES
#     if data['operation'] == 'insert':
#         es.index(index='your_index', id=data['id'], body=data['record'])
#     elif data['operation'] == 'update':
#         es.update(index='your_index', id=data['id'], body={'doc': data['record']})
#     elif data['operation'] == 'delete':
#         es.delete(index='your_index', id=data['id'])
#     return "ES updated successfully"
